﻿using System.Text.Json;
using System.Text.Json.Serialization;

namespace AutomaticSubtitles.Service.Infrastructure.JsonConverter
{
    public class DoubleConverter : JsonConverter<double>
    {
        public string DoubleFormat { get; set; } = "#0.00000";

        public override double Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            return double.Parse(reader.GetString()); ;
        }

        public override void Write(Utf8JsonWriter writer, double value, JsonSerializerOptions options)
        {
            writer.WriteStringValue(value.ToString(DoubleFormat));
        }
    }
}
